import math
import fractions


def set_chinese_font():
    """设置中文字体"""
    plt.rcParams['font.sans-serif'] = ['SimHei', 'Microsoft YaHei', 'DejaVu Sans']
    plt.rcParams['axes.unicode_minus'] = False  # 解决负号显示问题

set_chinese_font()


def rational_number_demo():
    f1 = fractions.Fraction(3,4)
    f2 = fractions.Fraction(2,5)

    print(f"分数1:{f1}")
    print(f"分数2:{f2}")
    print(f"加法: {f1} + {f2} = {f1 + f2}")
    print(f"减法：{f1} - {f2} = {f1 - f2}")
    print(f"乘法: {f1} * {f2} = {f1 * f2}")
    print(f"除法: {f1} / {f2} = {f1 / f2}")

    # 实数运算
    print(f"\nΠ的近似值: {math.pi}")
    print(f"e的近似值: {math.e}" )
    print(f"根号2的近似值:{math.sqrt(2)}" )


rational_number_demo()
